package com.gcalsync.log;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Display;

/**
 * @author Thomas Oldervoll, thomas@zenior.no
 */
public class ErrorHandler {

    public static boolean debugMode = true;
    public static Display display;
    public static StringBuffer log;

    public static void showError(String message, Throwable t) {
        display.setCurrent(getErrorAlert(message, t));
    }

    public static Alert getErrorAlert(String message, Throwable t) {
        if (t != null) {
            t.printStackTrace();
        }
        log.append(t + "\n");
        if (debugMode) {
            message += "\n" + t + "\n" + log.toString();
        }
        Alert alert = new Alert("Error", message, null, AlertType.ERROR);
        alert.setTimeout(Alert.FOREVER);
        return alert;
    }
}
